<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #dv {
            height: 200px;
            width: 200px;
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <input type="button" value="添加" id="btn">
    <div id="dv">

    </div>
    <script>
        var odiv = document.getElementById('dv');
        var btn = document.getElementById('btn');
        var arr = ['zxj', 'gqq', 'pyr', 'gb'];
        btn.onclick = function () {
            var str = "<ul>";
            for (var i = 0; i < arr.length; i++) {
                str += "<li>" + arr[i] + "</li>";
            }
            str = str + "</ul>"
            odiv.innerHTML = str;

            var li = odiv.getElementsByTagName('li');
            for (var i = 0; i < li.length; i++) {
                li[i].onmouseover = function () {
                    this.style.backgroundColor = 'red';
                }
                li[i].onmouseout = function () {
                    this.style.backgroundColor = '';
                }
            }
        }
    </script>
</body>

</html>